\documentclass{ctexart}
\usepackage{float}%解决图片乱跑问题
\usepackage{geometry}%设置页面大小边距等
\usepackage{authblk}%作者机构等信息
\usepackage{graphicx}%插入图片
\usepackage{epstopdf}
\usepackage{subfigure}
\usepackage{amssymb}%为了用\mathbb
\usepackage{amsmath}%数学方程的显示
\usepackage{listings}%插入代码
\usepackage{fancyhdr}%设置页眉页脚
\usepackage{lastpage}%总页数
\usepackage{tikz}
\usepackage{listings}%插入代码
\usepackage{hyperref}%引用网页
\usepackage{xcolor}%实现代码颜色高亮
\geometry{a4paper,left=2cm,right=2cm,top=2cm,bottom=2cm}%一定要放在前面！
\lstset{basicstyle=\ttfamily,columns=flexible,
%keywordstyle=\bf\color{blue},
commentstyle=\it\color[RGB]{0,96,96},
numberstyle=\color[RGB]{0,192,192},
backgroundcolor=\color[RGB]{220,220,220}}%代码块背景色为浅灰色}


\pagestyle{fancy}%设置页眉页脚
\lhead{陈冠宇\ 3200102033}%页眉左
\chead{Numerical Analysis}%页眉中
\rhead{Project}%章节信息
\cfoot{\thepage/\pageref{LastPage}}%当前页，记得调用前文提到的宏包
\rfoot{School of Mathematical Sciences in ZJU}
\renewcommand{\headrulewidth}{0.1mm}%页眉线宽，设为0可以去页眉线
\renewcommand{\footrulewidth}{0.1mm}%页脚线宽，设为0可以去页眉线
\setlength{\headwidth}{\textwidth}

\newtheorem{theorem}{Theorem}
\newtheorem{proof}{Proof}
\newtheorem{solution}{Solution:}
\newtheorem{remark}{Remark}

\hypersetup{%设置网页链接颜色等
    colorlinks=true,%链接将会有颜色，默认是红色
    urlcolor=blue,%链接到网站的链接将会变为蓝绿色（cyan）
    }

\title{Programming questions of Chapter3}
\everymath{\displaystyle}
\begin{document}
\section*{Theoretical questions of Chapter3}
\subsection*{\uppercase\expandafter{\romannumeral1} Program Readme}\
\subsubsection*{How to test}
(1)For every question, like Question A, we need to cancel the notes about function in funciton.h, only after that can we do Makefile.(In function.h, every function in question ABCDE are all applied. If something else is required, then change the default function class.)

(2)Windows Vscode: Input
\begin{lstlisting}
    mingw32-make A      //compile Question A
    mingw32-make BCD    //compile Question BCD
    mingw32-make E      //compile Question E
\end{lstlisting}
\subsubsection*{Code structure}
(a)Spline.h

Spline.h can basically do the spline interpolation by ppform and B-Spline respectively. Also in class "ppform" and "BSpline", we can also compute the approximation value and exact error value. For example, Question A, as we delete the notes about the function in function.h, then we can successfully run the makefile. Then we run
\begin{lstlisting}
./testA
\end{lstlisting}
Then we need to input the number of knots. For example, $N = 6$, then spline.h will output files as
\begin{lstlisting}
    //Put all the following .m files in Matlab and run directly.
    Cde_ppform.m           //Run directly to get interpolation and exact plot
    Code_ppform_Error.m     //Run directly to get the error plot
    Code_BSpline.m
    Code_BSpline_Error.m
\end{lstlisting}
The same as Question BCDE.

(b)class ppform
\begin{lstlisting}
ppform p;
vector<double> x,y;
p(x,y);
\end{lstlisting}
class BSpline
\begin{lstlisting}
BSpline C;
vector<double> x,y;
B(x,y,3);//cubic
\end{lstlisting}

\newpage
\subsection*{\uppercase\expandafter{\romannumeral2} Problems}
\subsection*{Modification in function.h is necessary for every single question. If you don't want to do it, run .m file directly in matlab.}
\subsection*{A.}
\begin{lstlisting}
./testA
    N       (like 6,11,21,41,81)
\end{lstlisting}
(1)Plots:
\begin{figure}[htbp]
\centering
\subfigure[A 6 knots complete]
{
    \begin{minipage}[b]{.3\linewidth}
        \centering
        \includegraphics[scale=0.4]{Figures/A_6knots_complete.png}
    \end{minipage}
}
\subfigure[A 11 knots complete]
{
 	\begin{minipage}[b]{.3\linewidth}
        \centering
        \includegraphics[scale=0.4]{Figures/A_11knots_complete.png}
    \end{minipage}
}
\subfigure[A 21 knots complete]
{
 	\begin{minipage}[b]{.3\linewidth}
        \centering
        \includegraphics[scale=0.4]{Figures/A_21knots_complete.png}
    \end{minipage}
}

\subfigure[A 41 knots complete]
{
 	\begin{minipage}[b]{.3\linewidth}
        \centering
        \includegraphics[scale=0.4]{Figures/A_41knots_complete.png}
    \end{minipage}
}
\subfigure[A 81 knots complete]
{
 	\begin{minipage}[b]{.3\linewidth}
        \centering
        \includegraphics[scale=0.4]{Figures/A_81knots_complete.png}
    \end{minipage}
}
\caption{$f(x) = \frac{1}{1+25x^2}$ interpolation}
\end{figure}



(2)Error at each midpoints of the subintervals are as follows:

\begin{center}
  \begin{tabular}{|c|c|c|c|c|c|}

  \hline
  % after \\: \hline or \cline{col1-col2} \cline{col3-col4} ...
  N & 6 & 11 & 21 & 41 & 81 \\
  \hline
  Error & 0.4217 & 0.0205289 & 0.00316894 & 2.7536e-04 & 1.6090e-05 \\
  \hline
\end{tabular}
\end{center}
(3)Analysis
The error $\epsilon = |f(x)-s(x)|$ is considered as maximal error at the midpoints of every subintervals. Then we have
$$\epsilon = |f(x)-(x)|\leq \frac{h^4}{16}\max_{x\in [a,b]}|f^4{x}|=\frac{C}{(N-1)^4}$$
That is the error and the number N has relation of
$ln(E_\infty) = -4ln(N-1)+ln(C)$, the error has fourth order convergence rate
\newpage
\subsection*{BCD}
\begin{lstlisting}
./testBCD
    11 -5 5
or
    10 -4.5 4.5
\end{lstlisting}
(1)Plots: Function $\&$ Error

\begin{figure}[htp]
\centering
\subfigure[A 11 knots B-Spline]
{
    \begin{minipage}[b]{.45\linewidth}
        \centering
        \includegraphics[scale=0.5]{Figures/BCD_11knots_Bspline_complete.png}
    \end{minipage}
}
\subfigure[A 11 knots B-Spline Error]
{
    \begin{minipage}[b]{.45\linewidth}
        \centering
        \includegraphics[scale=0.5]{Figures/BCD_11knots_Bspline_complete_error.png}
    \end{minipage}
}
\caption{$f(x) = \frac{1}{1+x^2}$ Interpolation 11 knots in $[-5,5]$}
\end{figure}

\begin{figure}[htp]
\centering
\subfigure[A 10 knots B-Spline]
{
    \begin{minipage}[b]{.45\linewidth}
        \centering
        \includegraphics[scale=0.5]{Figures/BCD_10knots_Bspline_complete.png}
    \end{minipage}
}
\subfigure[A 10 knots B-Spline Error]
{
    \begin{minipage}[b]{.45\linewidth}
        \centering
        \includegraphics[scale=0.5]{Figures/BCD_10knots_Bspline_complete_error.png}
    \end{minipage}
}
\caption{$f(x) = \frac{1}{1+x^2}$ Interpolation 10 knots in $[-4.5,4.5]$}
\end{figure}


As we can see, the former B-Spline is more accurate.

(2)Error table:

\begin{center}
  \begin{tabular}{|c|c|c|c|c|c|c|c|}
    \hline
    % after \\: \hline or \cline{col1-col2} \cline{col3-col4} ...
    Knots & -3.5 & -3 & -0.5 & 0 & 0.5 & 3 & 3.5 \\
    \hline
     Error &0.000669568& 0 & 0.0205289 & 0 & 0.0205289 & 0& 0.000669568 \\
    \hline
    Error &0& 0.00443972 & 0& 0.109398 & 0& 0.00443972 &0\\
    \hline
  \end{tabular}
\end{center}
\newpage
\subsection*{E}
Cancel notes of function.h x(t).
\begin{lstlisting}
mingw32-make E
./testE
\end{lstlisting}
Cancel notes of function.h y(t).
\begin{lstlisting}
mingw32-make E
./testE
\end{lstlisting}
Then Open file with matlab. We have had the array t,x/t,y, then plot x,y.

Take $x^2+(\frac{3}{2}y-\sqrt{|x|})^2=3$ as $t\in [-\frac{\pi}{2},\frac{3\pi}{2}]$ with
$$\left\{
\begin{aligned}
x&=\sqrt{3}\cos t;\\
y&=\frac{2}{3}\sqrt{3}\sin t+\sqrt{|\sqrt{3}\cos t|}
\end{aligned}\right.$$
(1)Plots

\begin{figure}[htp]
\centering
\subfigure[A 10 knots complete]
{
    \begin{minipage}[b]{.3\linewidth}
        \centering
        \includegraphics[scale=0.4]{Figures/E_10_knots_complete.png}
    \end{minipage}
}
\subfigure[A 40 knots complete]
{
    \begin{minipage}[b]{.3\linewidth}
        \centering
        \includegraphics[scale=0.4]{Figures/E_40_knots_complete.png}
    \end{minipage}
}
\subfigure[A 160 knots complete]
{
    \begin{minipage}[b]{.3\linewidth}
        \centering
        \includegraphics[scale=0.4]{Figures/E_160_knots_complete.png}
    \end{minipage}
}

\subfigure[A 10 knots natural]
{
    \begin{minipage}[b]{.3\linewidth}
        \centering
        \includegraphics[scale=0.4]{Figures/E_10_knots_natural.png}
    \end{minipage}
}
\subfigure[A 40 knots natural]
{
    \begin{minipage}[b]{.3\linewidth}
        \centering
        \includegraphics[scale=0.4]{Figures/E_40_knots_natural.png}
    \end{minipage}
}
\subfigure[A 160 knots complete]
{
    \begin{minipage}[b]{.3\linewidth}
        \centering
        \includegraphics[scale=0.4]{Figures/E_160_knots_natural.png}
    \end{minipage}
}
\caption{$x^2+\left(\frac{3}{2}y-\sqrt{|x|}\right)^2=3$}
\end{figure}

(2)As we can see, the natural spline boundary conditions are more appropriate, cause it is more accurate.
\subsection*{Sum Up}
In this project, i tried to make user-experience better. But finally, i found it is difficult to satisfy all the requirements of different questions. However, as we can see, the program i made, for question A and B which only have single function, is quiet convenient. But for E, i need to change function.h frequently, which is quite annoying not only in my test process.

I can figure another thing: DLL is killing people! Maybe you have something in trouble in your test, please contact me on DingDing or something.
\end{document}
